import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.junit.Test;
import service.DemoService;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;

public class getUrl {
    DemoService service = new DemoService();
    //接口地址
    String url="http://www.ghostoact.com/api/pics/getpicforR";
    //图片保存地址
    String dir="D:\\img\\randomPic";

    /**
     * 测试接口
     * @throws MalformedURLException
     */
    @Test
    public void getJSON() throws  MalformedURLException {
        String json= service.getJSON(url);
        System.out.println(json);
    }

    /**
     * 测试从json分离图片地址
     */
    @Test
    public void getUrl(){
        ArrayList<String> list = service.getImgList(url);

        for (String str:list){
            System.out.println("地址："+str);
        }
    }

    /**
     * 测试保存到本地
     * @throws MalformedURLException
     */
    @Test
    public  void  savaFile() throws MalformedURLException {
        service.saveFile("http://wx3.sinaimg.cn/large/a910d180gy1fog5upv37zj21ye0u07jj.jpg","D:\\img\\randomPic");
    }


    /**
     * 爆破单个接口
     * @throws MalformedURLException
     */
    @Test
    public  void  getlist() throws MalformedURLException {
        ArrayList<String> imgList = service.getImgList(url);

        for (String imgurl:imgList){
            System.out.print("当前地址：http:"+imgurl);
            service.saveFile("http:"+imgurl,dir);
        }
    }



    /**
     * 测试爆破图片库
     * 循环10000测试接口获取json
     * json分离出图片地址
     * 将图片保存到本地
     * @throws MalformedURLException
     */
    @Test
    public void  baopo () throws MalformedURLException {
        for (int a=0; a<10000;a++){
            getlist();
        }
    }



}
